package com.guguskins.back.controller;


import com.guguskins.back.entity.GuInviteNum;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuInviteNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/inviteNum")
public class GuInviteNumController {

    @Autowired
    private GuInviteNumService inviteNumService;

    @GetMapping("/back/list")
    public ResultVo backList() {

        return ResultVo.success(inviteNumService.backList());
    }

    @PostMapping("/back/add")
    public ResultVo backAdd(@RequestBody GuInviteNum inviteNum) {
        if(ObjectUtils.isEmpty(inviteNum.getInvitePrizeId())){
            return ResultVo.success("奖品不能为空");
        }
        inviteNum.insert();
        return ResultVo.success("操作成功");
    }

    @PostMapping("/back/edit")
    public ResultVo backEdit(@RequestBody GuInviteNum inviteNum) {
        inviteNum.updateById();
        return ResultVo.success("操作成功");
    }

    @GetMapping("/back/AllList")
    public ResultVo findAll() {
        return ResultVo.success(inviteNumService.backList(), "查找成功");
    }
}
